﻿Imports System.IO.IsolatedStorage
Imports Windows.Storage.Streams
Imports Runa.Common.Helper
Imports Runa.Foundation.IO
Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports System.Text.RegularExpressions
Imports Microsoft.Xna.Framework
Imports System.IO

#If WINDOWS Then
Imports System.Windows.Forms
#End If

Module Program

    <MTAThread()>
    Sub Main()
        g_fileStorage = New IsolatedFileStorageGameDirectory()

#If DEBUG Then
        If g_fileStorage.DirectoryExists("山桂") Then
            g_fileStorage.DeleteDirectory("山桂", True)
        End If
#Else
        If fileStorage.FileExists("Sample.zip") = False Then
#End If

#If NETFX_CORE Then
        Dim asm = GetType(Program).Assembly()
        Dim resources = asm.GetManifestResourceNames()
        For Each r In resources
            Using rs = asm.GetManifestResourceStream(r)
                Dim path = System.IO.Path.GetFileName(r)
                Dim lst As New List(Of Integer)
                For i As Integer = 0 To path.Length - 1
                    If path(i) = "." Then
                        lst.Add(i)
                    End If
                Next
                Dim index = If(lst.Count > 2, lst(lst.Count - 2) + 1, 0)
                Dim fn = path.Substring(index)
                Using isolatedFileStream = g_fileStorage.OpenFile(fn, Runa.Foundation.IO.FileMode.OpenOrCreate)
                    rs.CopyTo(isolatedFileStream)
                    isolatedFileStream.Flush()
                    isolatedFileStream.Dispose()
                End Using
            End Using
        Next
#End If

#If Not Debug Then
        End If
#End If

        Global.Windows.UI.Xaml.Application.Start(Function(p) New Global.Runa.Metro.App())
        Debug.WriteLine("Main finished.")
    End Sub

End Module